package com.shy.controller;

import com.github.pagehelper.PageInfo;
import com.shy.config.model.R;
import com.shy.entity.Customer;
import com.shy.entity.Tran;
import com.shy.service.TranService;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/tran")
public class TranController {
    @Resource
    private TranService tranService;

    @ApiOperation("分页查询交易列表")
    @GetMapping("/pageList")
    public R<PageInfo<Tran>> pageList(@RequestParam Integer current, @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        PageInfo<Tran> tranList = tranService.queryTranPageList(current, pageSize);
        return R.success(tranList);
    }

    @ApiOperation("查询交易详情")
    @GetMapping("/detail/{tranId}")
    public R<Tran> queryTranDetailById(@PathVariable Integer tranId) {
        Tran tran = tranService.queryTranDetailById(tranId);
        return R.success(tran);
    }
    @ApiOperation("修改交易信息")
    @PutMapping("/editTran")
    public R<String> editTran(@RequestBody Tran tran) {
        Boolean editTran = tranService.modifyTran(tran);
        return R.HANDLE(editTran);
    }
    @ApiOperation("删除交易信息")
    @DeleteMapping("/batchDelete/{tranIds}")
    public R<String> deleteTran(@PathVariable List<Integer> tranIds) {
        Boolean deleteTran = tranService.deleteTranByIds(tranIds);
        return R.HANDLE(deleteTran);
    }
    @ApiOperation("新增客户交易")
//    @PreAuthorize("hasAuthority('xxx')")
    @PostMapping("/switchTran")
    public R<String> saveTran(@RequestBody Tran tran) {
        Boolean saved = tranService.saveTran(tran);
        return R.HANDLE(saved);
    }
}
